/**
 * 
 */
package model;

import java.util.Random;

import common.DataManager;


/**
 * @author Bill
 *
 */
public class WaveFactory {
	
	public static Wave getWave(int waveNum, int level){
		Wave wave = new Wave();
		wave.setWaveDescription("<html> Prepare for wave #"+(waveNum+1)+"!<br><br>");
		TrailTile firstTrailTile = (TrailTile)DataManager.getTrail(level).get(0);
		switch(waveNum){
		case 0: 
			if(level == 1) {
				wave.setWaveDescription(wave.getWaveDescription()+((new Pzombiedactyl(firstTrailTile)).getDescription().substring(6)));
				wave.setWaveDescriptionDuration(8000);
			}
			else wave.setWaveDescription(wave.getWaveDescription()+("A flock of Pzombiedactyls is approaching!</html>"));
			for(int i = 0; i < 5*level; i++) {
				WaveEntity e = new WaveEntity(new Pzombiedactyl(firstTrailTile), 2.0f/level);
				wave.add(e);
			}
			break;
		case 1: 
			if(level == 1) {
				wave.setWaveDescription(wave.getWaveDescription()+((new Trizombietops(firstTrailTile)).getDescription().substring(6)));
				wave.setWaveDescriptionDuration(8000);
			}
			else wave.setWaveDescription(wave.getWaveDescription()+("A stampede of Trizombietops can be heard in the distance...</html>"));
			for(int i = 0; i < 6*level; i++) {
				WaveEntity e = new WaveEntity(new Trizombietops(firstTrailTile), 1.0f/level);
				wave.add(e);
			}
			break;
		case 2: 
			if(level == 1) {
				wave.setWaveDescription(wave.getWaveDescription()+((new Brontozombie(firstTrailTile)).getDescription().substring(6)));
				wave.setWaveDescriptionDuration(8000);
			}
			else wave.setWaveDescription(wave.getWaveDescription()+("A large herd of Brontozombies is coming!</html>"));
			for(int i = 0; i < 3*level; i++) {
				WaveEntity e = new WaveEntity(new Brontozombie(firstTrailTile), 3.0f/level);
				wave.add(e);
			}
			break;
		case 3: 
			if(level == 1) {
				wave.setWaveDescription(wave.getWaveDescription()+((new Zombloceraptor(firstTrailTile)).getDescription().substring(6)));
				wave.setWaveDescriptionDuration(8000);
			}
			else wave.setWaveDescription(wave.getWaveDescription()+("A ravenous pack of Zombloceraptors approaches!</html>"));
			for(int i = 0; i < 20*level; i++) {
				WaveEntity e = new WaveEntity(new Zombloceraptor(firstTrailTile), 0.3f/level);
				wave.add(e);
			}
			break;
		case 4: {
			wave.setWaveDescription(wave.getWaveDescription()+("Speedy zombosaurs can be just as dangerous as strong ones...</html>"));
			for(int i = 0; i < 2+2*level; i++){
				WaveEntity e = new WaveEntity(new Zombloceraptor(firstTrailTile), 7.0f);
				wave.add(e);
				for(int j = 0; j < 3*level+2*i; j++){
					e = new WaveEntity(new Zombloceraptor(firstTrailTile), 0.2f);
					wave.add(e);
					e = new WaveEntity(new Pzombiedactyl(firstTrailTile), 0.2f);
					wave.add(e);
				}
			}
			break;
		}
		case 5: {
			wave.setWaveDescription(wave.getWaveDescription()+("Strong zombosaurs can be just as dangerous as speedy ones...</html>"));
			for(int i = 0; i < 3+2*level; i++){
				WaveEntity e = new WaveEntity(new Trizombietops(firstTrailTile), 5.0f);
				wave.add(e);
				e = new WaveEntity(new Brontozombie(firstTrailTile), 0.5f);
				wave.add(e);
				e = new WaveEntity(new Trizombietops(firstTrailTile), 0.5f);
				wave.add(e);
			}
			break;
		}
		case 6: {
			wave.setWaveDescription(wave.getWaveDescription()+("Zombosaurs everywhere!</html>"));
			for(int i = 0; i < 4+3*level; i++){
				WaveEntity e = new WaveEntity(new Trizombietops(firstTrailTile), 0.7f/level);
				wave.add(e);
				e = new WaveEntity(new Brontozombie(firstTrailTile), 0.7f/level);
				wave.add(e);
				e = new WaveEntity(new Zombloceraptor(firstTrailTile), 0.7f/level);
				wave.add(e);
				e = new WaveEntity(new Pzombiedactyl(firstTrailTile), 0.7f/level);
				wave.add(e);
			}
			break;
		}
		case 7: {
			wave.setWaveDescription(wave.getWaveDescription()+("Ahhh!!!</html>"));
			WaveEntity e = new WaveEntity(new Zombloceraptor(firstTrailTile), 5.0f/level);
			wave.add(e);
			for(int i = 0; i < 10+10*level; i++){
				e = new WaveEntity(new Zombloceraptor(firstTrailTile), 0.3f/level);
				wave.add(e);
			}
			e = new WaveEntity(new Brontozombie(firstTrailTile), 5.0f/level);
			wave.add(e);
			for(int i = 0; i < 4+level; i++){
				e = new WaveEntity(new Brontozombie(firstTrailTile), 1.0f);
				wave.add(e);
			}
			e = new WaveEntity(new Pzombiedactyl(firstTrailTile), 5.0f/level);
			wave.add(e);
			for(int i = 0; i < 6+5*level; i++){
				e = new WaveEntity(new Pzombiedactyl(firstTrailTile), 0.5f/level);
				wave.add(e);
			}
			e = new WaveEntity(new Trizombietops(firstTrailTile), 5.0f/level);
			wave.add(e);
			for(int i = 0; i < 5+3*level; i++){
				e = new WaveEntity(new Trizombietops(firstTrailTile), 0.6f/level);
				wave.add(e);
			}
			break;
		}
		case 8: {
			wave.setWaveDescription(wave.getWaveDescription()+("So many zombosaurs!!</html>"));
			Random randomGenerator = new Random();
			int numEnemies = randomGenerator.nextInt(20*level)+30;	//generates a random number of enemies for the wave
			for(int i = 0; i < numEnemies; i++){
				int nextEnemyType = randomGenerator.nextInt()%4;
				float nextEnemyDelay = randomGenerator.nextFloat()*3.0f/level;
				WaveEntity e;
				switch(nextEnemyType){
				case 0:
					e = new WaveEntity(new Pzombiedactyl(firstTrailTile), nextEnemyDelay); break;
				case 1:
					e = new WaveEntity(new Trizombietops(firstTrailTile), nextEnemyDelay); break;
				case 2:
					e = new WaveEntity(new Brontozombie(firstTrailTile), nextEnemyDelay); break;
				case 3:
					e = new WaveEntity(new Zombloceraptor(firstTrailTile), nextEnemyDelay); break;
				default:
					e = new WaveEntity(new Zombloceraptor(firstTrailTile), nextEnemyDelay);
				}
				wave.add(e);
			}
			break;
		}
		case 9: {
			if(level == 1) {
				wave.setWaveDescription(wave.getWaveDescription()+((new TyrannozombieRex(firstTrailTile)).getDescription().substring(6)));
				wave.setWaveDescriptionDuration(8000);
			}
			else if(level == 2) {
				wave.setWaveDescription(wave.getWaveDescription()+("A wild Tyrannozombie Rex appeared!</html>"));
			}
			else if(level == 3){
				wave.setWaveDescription(wave.getWaveDescription()+("The Tyrannozombie Rex is coming back! <br>And this time he brought friends...</html>"));
				for(int i = 0; i < 3; i++){
					WaveEntity e = new WaveEntity(new TyrannozombieRex(firstTrailTile), 4.0f);
					wave.add(e);
					for(int j = 0; j < 15; j++){
						e = new WaveEntity(new Zombloceraptor(firstTrailTile), 0.1f);
						wave.add(e);
					}
					e = new WaveEntity(new Zombloceraptor(firstTrailTile), 2.0f);
					wave.add(e);
				}
			}
			WaveEntity e = new WaveEntity(new TyrannozombieRex(firstTrailTile), 2.0f);
			wave.add(e);
			break;
		}
		}
		return wave;
	}

}
